package date.Exa1;

import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class InstantStudy {
    public static void main(String[] args) throws InterruptedException {
        //获取当前时间线对象
        Instant start = Instant.now();
        System.out.println("获取当前Instant对象 : "+start);
        //将此时间线转换为中国时区时间
        ZonedDateTime time = start.atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println("此时间线的中国时间为: "+time);
        //打印当前时间戳
        long timeStamp = start.toEpochMilli();
        System.out.println("时间戳为："+timeStamp);
        Thread.sleep(2000);
        Instant end = Instant.now();
        //计算两个时间差
        Duration duration = Duration.between(start,end);
        long mills = duration.toMillis();
        System.out.println("时间差为： "+mills+" mills");
    }
}
